package com.yoomiito.app.ui.order.list

import cn.droidlover.xdroidmvp.net.ApiException
import cn.droidlover.xdroidmvp.net.ApiSubscriber
import cn.droidlover.xdroidmvp.net.XApi
import com.yoomiito.app.base.AppConfig
import com.yoomiito.app.base.BaseLazyFragmentPresenter
import com.yoomiito.app.model.bean.ExamineBean
import com.yoomiito.app.model.bean.ExamineBean1
import com.yoomiito.app.model.bean.OrderInfo
import com.yoomiito.app.model.bean.OrderList
import com.yoomiito.app.net.YmApi
import com.yoomiito.app.utils.YMToast

class OrderFmPresenter2(appConfig: AppConfig) : BaseLazyFragmentPresenter<OrderFragment2>(appConfig) {

    fun queryOrderList(page :Int,key: Int, orderType: Int) {
        YmApi.getYmService()
                .queryOrderList(page,key, orderType)
                .compose(v.bindToLifecycle())
                .compose(XApi.getApiTransformerData<OrderList>())
                .compose(XApi.getScheduler())
                .subscribe(object : ApiSubscriber<OrderList>() {
                    override fun onSuccess(orderList: OrderList) {
                        v.setData(orderList)
                    }

                    override fun onFail(error: ApiException) {

                    }
                })
    }

    fun queryOfflineList() {
        YmApi.getYmService()
                .queryOfflineList()
                .compose(v.bindToLifecycle())
                .compose(XApi.getApiTransformerData<List<OrderInfo>>())
                .compose(XApi.getScheduler())
                .subscribe(object : ApiSubscriber<List<OrderInfo>>() {
                    override fun onSuccess(orderList: List<OrderInfo>) {
                        v.setData1(orderList)

                    }

                    override fun onFail(error: ApiException) {

                    }
                })
    }

    fun offExamine(data: ExamineBean) {
        YmApi.getYmService()
                .offExamine(data)
                .compose(v.bindToLifecycle())
                .compose(XApi.getApiTransformerData<List<OrderInfo>>())
                .compose(XApi.getScheduler())
                .subscribe(object : ApiSubscriber<List<OrderInfo>>() {
                    override fun onSuccess(orderList: List<OrderInfo>) {
                        v.setData()

                    }

                    override fun onFail(error: ApiException) {
                        YMToast.showText(error.msg)
                    }
                })
    }
    fun offExamine1(data: ExamineBean1) {
        YmApi.getYmService()
                .offExamine1(data)
                .compose(v.bindToLifecycle())
                .compose(XApi.getApiTransformerData<List<OrderInfo>>())
                .compose(XApi.getScheduler())
                .subscribe(object : ApiSubscriber<List<OrderInfo>>() {
                    override fun onSuccess(orderList: List<OrderInfo>) {
                        v.setData()

                    }

                    override fun onFail(error: ApiException) {
                        YMToast.showText(error.msg)

                    }
                })
    }

}
